<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>添加管理员</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/index.css">
        <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/index.js"></script>
         <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->

    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                   <form class="layui-form">
                  <div class="layui-form-item">
                      <label for="username" class="layui-form-label">
                          <span class="x-red">*</span>登录名
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="username" disabled="true" name="username" required="" lay-verify="required"
                          autocomplete="off" class="layui-input ">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>将会成为您唯一的登入名
                      </div>
                  </div>
                  
                
                    
                      
                      <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                       <span class="x-red">*</span>绑定菜单
                    </label>
                    <div id="aaa" class="layui-input-inline">
                        <select  id="role"  
                        autocomplete="off" class="layui-input">
                        <option value="1">员工</option>
                        <option value="78">管理员</option>
                        	<option value="79">超级管理员</option>
                        	
	                        
	
                     </select>
                    </div>
                </div>
                
                
                 
                  <div class="layui-form-item">
                      <label for="L_pass" class="layui-form-label">
                          <span class="x-red">*</span>密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_pass" name="pass" required="" lay-verify="pass"
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          6到16个字符
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                          <span class="x-red">*</span>确认密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_repass" name="repass" required="" lay-verify="repass"
                          autocomplete="off" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                      </label>
                      <input type="button" value="增加" id="add" class="layui-btn" >
                          
                     
                  </div>
              </form>
            </div>
        </div>
        <script>
     
		
        	layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;
               
            });
            
               		//生成角色选项

		
		//生成随机数
		var num = Math.floor(Math.random() * 99999 + 10000);
		$("#username").val(num);
            
            
            
        $("#add").click(function(){
							if($("#L_pass").val().length<6 )
							{
								alert('密码小于6');
								return;
							}
							if( $("#L_pass").val().length>12)
							{
								alert('密码大于12');
								return;
							}
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            alert('两次密码不一致');
                            return;
                        };
                        


               $.ajax({
		    type:"get",//请求方式
		    url:"http://localhost:16111/user/check_Administrator",
			dataType:"json",
		    data:{account:$("#username").val()},//传值
		   	xhrFields:{withCredentials: true},
		    success: function (data)
			{
		
				var user = eval('(' + JSON.stringify(data) + ')');
				if(user.data==="账号重复")
				{
					alert("随机账号重复，已重新生成账号");
					var num = Math.floor(Math.random() * 999999 + 100000);
					$("#username").val(num);
					return;
				}
		  }
		});
               
           
               $.ajax({
		    type:"post",//请求方式
		    url:"http://localhost:16111/user/create_Administrator",//上s层的路径		  
			dataType: "json",
		    xhrFields:{withCredentials: true},
		    data:{account: $("#username").val(),
			  pawd: $('#L_pass').val(),
			  role_name:$("#role").val()},//传值
		    success:function(res){
		    	
		    	if(res.data=="创建成功"){
		    		 layer.alert(res.data, {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                 parent.aaa();
                //关闭当前frame
                parent.layer.close(index);
            });
		    	}else{
		    			 layer.alert(res.error, {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                 parent.aaa();
                //关闭当前frame
                parent.layer.close(index);
            });
		    	}
		    	
		    	
		    },error:function(xhr){
		    	
		     
            	 layer.alert(JSON.stringify(xhr), {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                 parent.aaa();
                //关闭当前frame
                parent.layer.close(index);
            });
		    
		    }
		   
		})   
               
             
		})
        
               

        </script>
        
    </body>

</html>
